/**
 * 版权所有 2009-2012山东新北洋信息技术股份有限公司
 * 保留所有权利。
 */
package com.linyaonan.leetcode.easy._101;

/**
 * @ProjectName: leetcode
 * @Package: com.linyaonan.leetcode.easy._101
 * @ClassName: SymmetricTreeNew
 * @Author: linyaonan
 * @Date: 2019/10/25 11:38
 */
public class SymmetricTreeNew {

    /**
     * 使用中序左遍历与中序右遍历每一个值进行修改
     * @param root
     * @return
     */
    public boolean isSymmetric(TreeNode root) {
        if (root == null) {
            return true;
        }
        return isSame(root.left, root.right);
    }

    private boolean isSame(TreeNode node1, TreeNode node2) {
        if (node1 == null && node2 == null) {
            return true;
        }
        if (node1 == null || node2 == null) {
            return false;
        }
        if (node1.val == node2.val) {
            boolean isLeftSame = isSame(node1.left, node2.right);
            if (isLeftSame) {
                return isSame(node1.right, node2.left);
            }
        }
        return false;
    }
}
